const TOKEN_NAME = "music_token";
const TOKEN_USER = "music_user";
const TOKEN_RECORD = "music_record";
/** 获取 token */
const getToken = () => localStorage.getItem(TOKEN_NAME);
/**设置 token */
const setToken = (value: String) =>
  localStorage.setItem(TOKEN_NAME, JSON.stringify(value));
/** 删除 token */
const removeToken = () => localStorage.removeItem(TOKEN_NAME);
/**获取用户信息 */
const getUser = () => JSON.parse(String(localStorage.getItem(TOKEN_USER)));
/**设置用户 */
const setUser = (value: Object) =>
  localStorage.setItem(TOKEN_USER, JSON.stringify(value));
/**删除用户 */
const removeUser = () => localStorage.removeItem(TOKEN_USER);
/**是否登录（有权限） */
const isAuth = () => !!getToken();
/** 存入播放记录*/
const setPlayHistory = (value: Object) =>
  localStorage.setItem(TOKEN_RECORD, JSON.stringify(value));
/**获取播放记录 */
const getPlayHistory = () =>
  JSON.parse(String(localStorage.getItem(TOKEN_RECORD)));

const getCommentLike = () =>
  JSON.parse(String(localStorage.getItem("comment_like"))) || [];

const setCommentLike = (value: any) =>
  localStorage.setItem("comment_like", JSON.stringify(value));

export {
  getToken,
  setToken,
  removeToken,
  isAuth,
  removeUser,
  getUser,
  setUser,
  setPlayHistory,
  getPlayHistory,
  getCommentLike,
  setCommentLike,
};
